package me.cxlr.shaopinghelper.util;

import android.content.Context;
import android.widget.Toast;

import androidx.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * ToastUtil
 *
 * @author ShanLunZhi
 */
public class ToastUtil {
    private static Toast toast;

    @IntDef(value = {LENGTH_SHORT, LENGTH_LONG})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Duration {
    }

    public static final int LENGTH_SHORT = 0;
    public static final int LENGTH_LONG = 1;

    public static void show(Context context, String text, @Duration int duration) {
        if (toast != null) {
            toast.cancel();
        }
        toast = Toast.makeText(context, text, duration);
        toast.show();
    }
}
